/**
 * Description: 任意两个无符号数相加, 不能用64位变量
 * File: big_plus.c |Time: 2021-07-17 11:15
 */
#include <stdio.h>
#include <string.h>

void add(unsigned a, unsigned b)
{
    char res[10] = {0};
    int flag = 0;
    char *p_a = (char *)&a;
    char *p_b = (char *)&b;
    int i, j;

    for (i = 0; i < sizeof(unsigned int); i++) 
    {
        res[i] = (*p_a + *p_b + flag) % 256;
        flag = (*p_a + *p_b + flag) > 255 ? 1: 0;
        p_a++;
        p_b++;
    }

    res[i] = flag;
    char tmp;

    for (i = 0, j = strlen(res) - 1; i < j; i++, j--) 
    {
        tmp = res[i];
        res[i] = res[j];
        res[j] = tmp;
    }

    printf("%lu\n", *((unsigned long*)res));
}

int main(int argc, const char *argv[])
{
    add(300, 215);
    
    return 0;
}
